package com.zhu.commentstatisticspublisher.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 *Mysql 数据源
 */
@Configuration
public class SecondDataSource {

        @Value("${spring.datasource.two.url}")
        private String url;

        @Value("${spring.datasource.two.username}")
        private String username;

        @Value("${spring.datasource.two.password}")
        private String password;

        @Value("${spring.datasource.two.driver-class-name}")
        private String driverClassName;


        /**
         * 配置数据源
         */

        @Bean(name="setSecondDataSource")
        public DataSource setDataSource(){
            DriverManagerDataSource dataSource=new DriverManagerDataSource();
            dataSource.setUrl(url);
            dataSource.setUsername(username);
            dataSource.setPassword(password);
            dataSource.setDriverClassName(driverClassName);
            return  dataSource;
        }

        /**
         * 配置jdbcTemplate
         */

        @Bean(name = "secondJdbcTemplate")
        public JdbcTemplate getJdbcTemplate(@Qualifier("setSecondDataSource")DataSource dataSource){
            return new JdbcTemplate(dataSource);
        }

}
